//
//  TravelDiaryCell.swift
//  GoTravel
//
//  Created by lanou3g on 16/3/7.
//  Copyright © 2016年 阮小瑞. All rights reserved.
//

import UIKit

class TravelDiaryCell: UITableViewCell,UIScrollViewDelegate {

    //设置图片属性
    var CellOfImageView:UIImageView?
    //设置轮播图属性
    var CellOfScrollView:UIScrollView?
    //设置轮播图上的图片属性
    var SVOfImage1:UIImageView?
    
    var SVOfImage2:UIImageView?
    
    var SVOfImage3:UIImageView?
    
    var SVOfImage4:UIImageView?
    
//    var SVOfImage5:UIImageView?
//    
//    var SVOfImage6:UIImageView?
//    
//    var SVOfImage7:UIImageView?
//    
//    var SVOfImage8:UIImageView?

    //设置发tuter用户头像、昵称、时间属性、地址
    var headImage:UIImageView?
    
    var nameLabel:UILabel?
    
    var sayLabel:UILabel?
    
    var timeLabel:UILabel?

    var addressTF:UITextField?

//重写cell的初始化方法以布局
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = UIColor.groupTableViewBackgroundColor()
        //布局图片
        self.CellOfImageView = UIImageView(frame: CGRectMake(4, self.contentView.frame.height * 0.1, self.contentView.frame.width - 8, self.contentView.frame.height * 0.65))
        self.CellOfImageView?.image = UIImage(named: "last1.jpg") //测试用
        self.CellOfImageView?.layer.masksToBounds = true
        self.CellOfImageView?.layer.cornerRadius = 5
        self.contentView.addSubview(CellOfImageView!)
        
        
        //布局轮播图
        self.CellOfScrollView = UIScrollView()
        //轮播图frame大小
        self.CellOfScrollView?.frame = CGRectMake(4,self.contentView.frame.height * 0.75 + 8,self.contentView.frame.width,self.contentView.frame.height * 0.2 - 8)
        //轮播图contentsize大小
        self.CellOfScrollView?.contentSize = CGSizeMake(self.contentView.frame.width * 1.3, (self.CellOfScrollView?.frame.height)!)
        self.CellOfScrollView?.delegate = self
        //是否整页滑动
        self.CellOfScrollView?.pagingEnabled = false
        //是否显示水平滚动条
        self.CellOfScrollView?.showsHorizontalScrollIndicator = true
        self.contentView.addSubview(CellOfScrollView!)
        
        //添加scrollView上的图片缩略图
        self.SVOfImage1 = UIImageView()
        self.SVOfImage1?.frame = CGRectMake(2, 0, (self.CellOfScrollView?.frame.height)!, (self.CellOfScrollView?.frame.height)!)
        self.SVOfImage1?.image = UIImage(named: "last2.jpg")//测试用
        self.SVOfImage1?.layer.masksToBounds = true
        self.SVOfImage1?.layer.cornerRadius = 5
        self.CellOfScrollView?.addSubview((self.SVOfImage1)!)
        
        self.SVOfImage2 = UIImageView()
        self.SVOfImage2?.frame = CGRectMake((self.SVOfImage1?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.SVOfImage1?.frame.height)!)
        self.SVOfImage2?.image = UIImage(named: "")//测试用
        self.SVOfImage2?.layer.masksToBounds = true
        self.SVOfImage2?.layer.cornerRadius = 5
        self.CellOfScrollView?.addSubview((self.SVOfImage2)!)
        
        self.SVOfImage3 = UIImageView()
        self.SVOfImage3?.frame = CGRectMake((self.SVOfImage2?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.CellOfScrollView?.frame.height)!)
        self.SVOfImage3?.image = UIImage(named: "")//测试用
        self.SVOfImage3?.layer.masksToBounds = true
        self.SVOfImage3?.layer.cornerRadius = 5
        self.CellOfScrollView?.addSubview((self.SVOfImage3)!)
        
        self.SVOfImage4 = UIImageView()
        self.SVOfImage4?.frame = CGRectMake((self.SVOfImage3?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.SVOfImage1?.frame.height)!)
        self.SVOfImage4?.image = UIImage(named: "")//测试用
        self.SVOfImage4?.layer.masksToBounds = true
        self.SVOfImage4?.layer.cornerRadius = 5
        self.CellOfScrollView?.addSubview((self.SVOfImage4)!)
        
        
        //布局用户头像、姓名、日期戳
        self.headImage = UIImageView()
        self.headImage?.frame = CGRectMake(10, 4, self.contentView.frame.height * 0.1 - 8, self.contentView.frame.height * 0.1 - 8)
        self.headImage?.layer.masksToBounds = true
        self.headImage?.layer.cornerRadius = 5
        self.headImage?.image = UIImage(named: "last1.jpg")//测试用
        self.contentView.addSubview(self.headImage!)
        
        self.nameLabel = UILabel()
        self.nameLabel?.frame = CGRectMake((self.headImage?.frame.maxX)! + 5, (self.headImage?.frame.minY)!, 50, (self.headImage?.frame.height)! * 0.51)
        self.nameLabel?.textColor = UIColor(red: 30/255 , green: 144/255, blue: 255/255, alpha: 1)
        self.nameLabel?.text = "ZLQ"//测试用
        self.contentView.addSubview(self.nameLabel!)
        
        self.sayLabel = UILabel()
        self.sayLabel?.frame = CGRectMake((self.nameLabel?.frame.minX)!, (self.nameLabel?.frame.maxY)! + (self.headImage?.frame.height)! * 0.01, self.contentView.frame.width * 0.7, (self.headImage?.frame.height)! * 0.48)
        self.sayLabel?.textColor = UIColor.blackColor()
        self.sayLabel?.text = "今天是答辩的日子"//测试用
        self.contentView.addSubview(self.sayLabel!)
        
        self.timeLabel = UILabel()
        self.timeLabel?.frame = CGRectMake((self.contentView.frame.width) - (self.SVOfImage1?.frame.width)! - 15, (self.CellOfScrollView?.frame.maxY)! + 5, (self.SVOfImage1?.frame.width)! + 27, UIScreen.mainScreen().bounds.height * 0.025)
        self.timeLabel?.backgroundColor = UIColor.clearColor()
        self.timeLabel?.text = "2016年3月17日" //测试用
        self.contentView.addSubview(self.timeLabel!)
        
        //addressTF
        self.addressTF = UITextField()
        self.addressTF?.frame = CGRectMake(self.contentView.frame.width * 0.05,(self.timeLabel?.frame.minY)!, (self.timeLabel?.frame.width)!, UIScreen.mainScreen().bounds.height * 0.025)
        self.addressTF?.text = "北京" //测试用
        self.contentView.addSubview(self.addressTF!)
    }
//重写初始化方法后系统会提示添加以下方法
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    
//重写布局方法
    override func layoutSubviews() {
        super.layoutSubviews()
        self.CellOfImageView?.frame =  CGRectMake(4, self.contentView.frame.height * 0.1, self.contentView.frame.width - 8, self.contentView.frame.height * 0.65)

        self.CellOfScrollView?.frame = CGRectMake(4,self.contentView.frame.height * 0.75 + 8,self.contentView.frame.width,self.contentView.frame.height * 0.2 - 8)

        self.SVOfImage1?.frame = CGRectMake(2, 0, (self.CellOfScrollView?.frame.height)!, (self.CellOfScrollView?.frame.height)!)

        self.SVOfImage2?.frame = CGRectMake((self.SVOfImage1?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.SVOfImage1?.frame.height)!)

        self.SVOfImage3?.frame = CGRectMake((self.SVOfImage2?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.CellOfScrollView?.frame.height)!)

        self.SVOfImage4?.frame = CGRectMake((self.SVOfImage3?.frame.maxX)! + 8, 0, (self.SVOfImage1?.frame.width)!, (self.SVOfImage1?.frame.height)!)
        
        self.headImage?.frame = CGRectMake(10, 4, self.contentView.frame.height * 0.1 - 8, self.contentView.frame.height * 0.1 - 8)

        self.nameLabel?.frame = CGRectMake((self.headImage?.frame.maxX)! + 5, (self.headImage?.frame.minY)!, 50, (self.headImage?.frame.height)! * 0.51)

        self.sayLabel?.frame = CGRectMake((self.nameLabel?.frame.minX)!, (self.nameLabel?.frame.maxY)! + (self.headImage?.frame.height)! * 0.01, self.contentView.frame.width * 0.7, (self.headImage?.frame.height)! * 0.48)
        
        self.timeLabel?.frame = CGRectMake((self.contentView.frame.width)*0.6, (self.CellOfScrollView?.frame.maxY)! + 5, self.contentView.frame.width * 0.5, UIScreen.mainScreen().bounds.height * 0.025)
        
        self.addressTF?.frame = CGRectMake(self.contentView.frame.width * 0.35,(self.timeLabel?.frame.minY)!, (self.timeLabel?.frame.width)!, UIScreen.mainScreen().bounds.height * 0.025)
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
